package com.cea.papyrus.diagram.activity.editpart;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.uml2.uml.Action;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.ReadExtentAction;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.figures.IconFigure;
import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagram.activity.figure.ActionFigure;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;

public class ReadExtentActionEditPart extends ActionEditPart {

	
	private static String INSTANCE="Read extent of ";
	
	public ReadExtentActionEditPart(GraphNode graphNode, ModelManager modelManager) {
		super(graphNode, modelManager);
	}

	public ReadExtentAction getUmlElement() {
		return (ReadExtentAction) super.getUmlElement();
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.editpart.GraphNodeWithSemanticEditPart#refreshVisuals()
	 */
	@Override
	protected void refreshVisuals() {
		Debug.debug(this, "refreshVisuals()", channel);

		Dimension size = getGraphNode().getSize();
		Point p = getGraphNode().getPosition();
		Rectangle r = new Rectangle(p, size);
		
		IFigure fig = getFigure();

		// Classifier
		if (fig instanceof IconFigure) {
			IconFigure icf = (IconFigure) getFigure();
			icf.setName(((NamedElement) getUmlElement()).getName());
		} else {
			Action currentAction = getUmlElement();
			com.cea.papyrus.umlutils.Element currentElement = new com.cea.papyrus.umlutils.Element(getUmlElement());
			((ActionFigure) fig).refreshColors(getGraphNode());
			((ActionFigure) fig).refreshPresentation(getPresentation(),currentAction, getGraphNode());
			
			boolean hasIcon = currentElement.hasIcon();
			boolean hasShape = currentElement.hasShape();
		
			((ActionFigure) fig).refreshStereotypes(((ActionFigure) fig).stereotypesLabel(this), getPresentation(), hasIcon, hasShape);
			((ActionFigure) fig).setName(currentAction.getName());

			// qualifiedName
			GraphNode gp= (GraphNode) getGraphNode().getContainer();
			((ActionFigure) fig).refreshQualifiedName(gp, getGraphNode(), getUmlElement());
			
			if( getUmlElement().getClassifier()!=null ){
				((ActionFigure) fig).setName(this.INSTANCE+getUmlElement().getClassifier().getName());
			}
		}  

		((GraphicalEditPart) getParent()).setLayoutConstraint(this, fig, r);
	}
}
